package logs

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app"
	"github.com/google/uuid"
)

func GidHandler() app.HandlerFunc {
	return func(ctx context.Context, c *app.RequestContext) {
		gid := c.Request.Header.Get("X-GID")
		if gid == "" {
			gid = uuid.New().String()
		}
		ctx = context.WithValue(ctx, "g-id", gid)

		c.Header("X-GID", gid)
		c.Next(ctx)
	}
}
